package com.zzyl;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.junit.Test;

import java.util.HashMap;

public class testHttp {
    @Test
    public void testGet(){
        String s = HttpUtil.get("https://www.baidu.com/");
        System.out.println(s);
    }
    @Test
    public void testGet2(){
        HttpResponse authorization = HttpUtil.createGet("http://localhost:8080/nursing/project/list")
                .header("authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjQ0ZTRiYjI1LTAyYTQtNDQ3OS04ZjVhLTY3OWViNTRjODg4MiJ9.htXl13ffYX-baSX1FwpKUfFpqUpDraVCe4apB_V6p04lB-2nXyiXEyZ4YCKda06xax7blCyvN8I3-Fe-S37upQ")
                .execute();

        System.out.println(authorization.body());


    }
    @Test
    public void testPost(){
        HashMap<String,Object> paramMap =new HashMap<>();
        paramMap.put("name", "护理项目测试");
        paramMap.put("orderNo", 1);
        paramMap.put("unit", "次");
        paramMap.put("price", 10.00);
        paramMap.put("image", "https://yjy-slwl-oss.oss-cn-hangzhou.aliyuncs.com/ae7cf766-fb7b-49ff-a73c-c86c25f280e1.png");
        paramMap.put("nursingRequirement", "无特殊要求");
        paramMap.put("status", 1);

        HttpResponse authorization = HttpUtil.createPost("http://localhost:8080/nursing/project")
                .header("authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjQ0ZTRiYjI1LTAyYTQtNDQ3OS04ZjVhLTY3OWViNTRjODg4MiJ9.htXl13ffYX-baSX1FwpKUfFpqUpDraVCe4apB_V6p04lB-2nXyiXEyZ4YCKda06xax7blCyvN8I3-Fe-S37upQ")
                .body(JSONUtil.toJsonStr(paramMap))
                .execute();
        System.out.println(authorization.body());
    }
}
